package testSystem;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.Game;
import FamilyTherapy.GCWindow;
import FamilyTherapy.Player;

public class testGame_gameLoop {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGameloop_1() throws Exception {
		
		
		
		
		//int currentPlayerNo = 1;
		//boolean endGame= false;
		Player[] p = { new Player("a", 1), new Player("b", 2) };
		
		//int pPosition=-1;
		p[0].addPoint(10);
		// output
		//final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		//System.setOut(new PrintStream(outContent));

		Game game = Game.class.newInstance();
		game.setNoOfPlayer(2);
		GCWindow gcWindow =new GCWindow();

		
		Method gameloopMethod = game.getClass().getDeclaredMethod(
				"gameLoop",GCWindow.class , Player[].class);
		//ArrayList before= p[0].getHoldingCard();
		gameloopMethod.setAccessible(true);
		//for input
		//String data = "r r"; 	//data to be input 
		//InputStream stdin = System.in; 
		/*
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			gameloopMethod.invoke(game,gcWindow, p);
			//pPosition = p[0].getPosition();
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		}
		
		String expected=
		"Game ended!\n"+
		"The Winner is: Player 0 : a!!!\n"+
		"Congratulations!!!!!!!!\n";*/
		gameloopMethod.invoke(game,gcWindow, p);
		
		gameloopMethod.setAccessible(false);
	



		
		//assertEquals(expected, outContent.toString());

	
		
	}
	@Test
	public void testGameloop_2() throws Exception {		
		
		//int currentPlayerNo = 1;
		//boolean endGame= false;
		Player[] p = { new Player("a", 1), new Player("b", 2) };
		
		//int pPosition=-1;
		p[0].addPoint(8);
		// output
		//final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		//System.setOut(new PrintStream(outContent));

		Game game = Game.class.newInstance();
		game.setNoOfPlayer(2);
		GCWindow gcWindow =new GCWindow();

		
		Method gameloopMethod = game.getClass().getDeclaredMethod(
				"gameLoop",GCWindow.class , Player[].class);
		//ArrayList before= p[0].getHoldingCard();
		gameloopMethod.setAccessible(true);
		//for input
		//String data = "r r"; 	//data to be input 
		//InputStream stdin = System.in; 
		/*
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			gameloopMethod.invoke(game,gcWindow, p);
			//pPosition = p[0].getPosition();
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		}
		
		String expected=
		"Game ended!\n"+
		"The Winner is: Player 0 : a!!!\n"+
		"Congratulations!!!!!!!!\n";*/
		gameloopMethod.invoke(game,gcWindow, p);
		
		gameloopMethod.setAccessible(false);
	



		
		//assertEquals(expected, outContent.toString());

	
		
	}
}
